/*
 * tablas_intranet.java
 *
 * Created on June 6, 2007, 12:14 PM
 */

package tablas_intranet;

import Lib.UtilLib;
import javax.swing.*; 
import java.util.*;
import metodos.ImplementacionMetodos;
/**
 * Correo electronico
 */

/**
 *
 * @author  jvicente
 */
public class tablas_intranet extends javax.swing.JFrame {

    private Vector listData;
    public static final int BP_MINIMO = 0;
    public static final int BP_MAXIMO = 0;
    public static final int NUM_TABLAS = 1;
    public static final double NUM_PORCENTAJE = 1/NUM_TABLAS;
    

    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jProgressBar1 = new javax.swing.JProgressBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("LLENADO DE TABLAS");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jList1);

        jProgressBar1.setStringPainted(true);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 335, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jProgressBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 344, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(19, 19, 19)
                .add(jProgressBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(26, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList jList1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
    
    public tablas_intranet() {
        jProgressBar1 = new JProgressBar();
        jList1 = new JList();
        listData = new Vector();
        jProgressBar1.setMinimum(BP_MINIMO);
        jProgressBar1.setMaximum(BP_MAXIMO);
        initComponents();
        
    }
    

    public void updateBar(int newValue) {
        jProgressBar1.setValue(newValue);
    }    

    public void setObjetToList(String elemString) {
        listData.addElement(elemString);
        jList1.setListData(listData);
    }
    public static void main(String args[]) {

        try {
            final tablas_intranet it = new tablas_intranet();
            java.util.Date fechaActual = new java.util.Date();
            String f = fechaActual.toString();

            ImplementacionMetodos m = new ImplementacionMetodos();
            UtilLib u = new UtilLib();
            java.awt.EventQueue.invokeLater(new Runnable() {

                public void run() {
                    it.pack();
                    it.setVisible(true);
                }
            });
            //EL PAGO A PROVEEDORES SE EJECUTA SOLO LOS DIAS VIERNES
            if (f.substring(0, 3).equals("Fri") && u.retornaInt(f.substring(11, 13)) < 13) {
                it.setObjetToList("ACTUALIZANDO TABLA LISTA_PAGO_PROVEEDORES");
                m.generarTablaPAGOPROVEEDORES(it);
                it.setObjetToList("TABLA LISTA_PAGO_PROVEEDORES COMPLETADA");
                System.out.println("1");
            }

        
          if (f.substring(0, 3).equals("Mon") && u.retornaInt(f.substring(11, 13)) < 13) {
                it.setObjetToList("ACTUALIZANDO TABLA LISTA DETALLE");
                m.generarTablaLISTADETALLE(it);
                it.setObjetToList("TABLA PROPIEDAD LISTA DETALLE");
                System.out.println("2");
          }

          
            if (u.retornaInt(f.substring(11, 13)) >= 19 && u.retornaInt(f.substring(11, 13)) < 21) {
                it.setObjetToList("ACTUALIZANDO TABLA GASTOS ADM.");
                m.generarTabla_gastos_admin_excep(it);
                it.setObjetToList("TABLA GASTOS ADM. COMPLETADA");
                it.setObjetToList("ACTUALIZANDO TABLA COSTOS OBRAS");
                m.generarTabla_COSTOS_OBRAS(it);
                it.setObjetToList("TABLA COSTOS OBRAS COMPLETADA");
                System.out.println("3");
            }
           if (u.retornaInt(f.substring(11, 13)) >= 21 && u.retornaInt(f.substring(11, 13)) < 23) {
                it.setObjetToList("ACTUALIZANDO PROCESO COSTOS ULTIMOS.");
                m.generarTabla_costos_ultimos(it);
                it.setObjetToList("PROCESO COSTOS ULTIMOS");
                System.out.println("4");
           }
            if (u.retornaInt(f.substring(11, 13)) >= 23) {
                //SE EJECUTARA TODOS LOS DIAS A LAS 6 DE LA TARDE
                it.setObjetToList("ACTUALIZANDO TABLA PROPIEDAD");
                m.generarTablaPROPIEDAD(it);
                it.setObjetToList("TABLA PROPIEDAD COMPLETADA");
                System.out.println("5");
            }
         
            try {
                Thread.sleep(2000);
                it.dispose();
            } catch (Exception e) {
                // ignore
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            // ignore
        }
    }
}